<?php

namespace IDock\Insurance\ZSIC;

use IDock\IDock\IDockEnums;
use IDock\IDock\IDockInterface;
use IDock\Insurance\LIHI\LIHIEnums;
use IDock\Insurance\ZSIC\Request\ElecPolicyDownloadRequest;
use IDock\Insurance\ZSIC\Request\NonCarProductListRequest;
use IDock\Insurance\ZSIC\Request\PolicyPaymentRequest;
use IDock\Insurance\ZSIC\Request\UnderwritingRecallRequest;
use IDock\Insurance\ZSIC\Request\UnderwritingRequest;
use IDock\Insurance\ZSIC\Request\UploadFileRequest;
use IDock\Insurance\ZSIC\Request\VehicleActualValueRequest;
use IDock\Insurance\ZSIC\Request\VehicleCheckRequest;
use IDock\Insurance\ZSIC\Response\ElecPolicyDownloadResponse;
use IDock\Insurance\ZSIC\Response\NonCarProductListResponse;
use IDock\Insurance\ZSIC\Response\UnderwritingRecallResponse;
use IDock\Insurance\ZSIC\Response\UnderwritingResponse;
use IDock\Insurance\ZSIC\Response\UploadFileResponse;
use IDock\Insurance\ZSIC\Response\VehicleActualValueResponse;
use IDock\Insurance\ZSIC\Request\PremiumInquiryRequest;
use IDock\Insurance\ZSIC\Request\RenewalInquiryRequest;
use IDock\Insurance\ZSIC\Request\VehicleModelRequest;
use IDock\Insurance\ZSIC\Response\PremiumInquiryResponse;
use IDock\Insurance\ZSIC\Response\RenewalInquiryResponse;
use IDock\Insurance\ZSIC\Response\VehicleCheckResponse;
use IDock\Insurance\ZSIC\Response\VehicleModelResponse;
use IDock\Printer\NonCar\NonCarInquiryPrinter;
use IDock\Printer\NonCar\NonCarInquirySinglePrinter;
use IDock\Printer\Premium\PremiumCoveragePrinter;
use IDock\Printer\Premium\PremiumInquiryPrinter;
use IDock\Printer\PremiumUnderwritingPrinter;
use IDock\Printer\SpecialClausesPrinter;
use IDock\Printer\VehicleActualValuePrinter;
use IDock\Visitor\EPolicyDownloadVisitor;
use IDock\Visitor\NonCar\NonCarInquiryVisitor;
use IDock\Visitor\NonCar\NonCarProductListVisitor;
use IDock\Visitor\NonCar\NonCarProductVisitor;
use IDock\Visitor\PolicyInfoVisitor;
use IDock\Visitor\PolicyPaymentVisitor;
use IDock\Visitor\Premium\PremiumInquiryVisitor;
use IDock\Visitor\ProposalRecallVisitor;
use IDock\Visitor\ProposalStatusVisitor;
use IDock\Visitor\RenewalInquiryVisitor;
use IDock\Visitor\UnderwritingRecallVisitor;
use IDock\Visitor\UploadFileVisitor;
use IDock\Visitor\VehicleActualValueVisitor;
use IDock\Visitor\VehicleModelVisitor;

/**
 * 太平保险
 */
class ZSICConstruct extends Builder implements IDockInterface
{

    protected $config = [];

    public function __construct($config)
    {
        $this->config = $config;
        $this->clientName = $config['clientName'] ?? '';
        $this->accessKey = $config['accessKey'] ?? '';
        $this->gateway = $config['gateway'] ?? '';
    }

    /**
     * 车型查询
     * @param VehicleModelVisitor $vehicleModelVisitor
     * @return VehicleModelResponse
     */
    public function vehicleModel(VehicleModelVisitor $vehicleModelVisitor): VehicleModelResponse
    {
        $request = new VehicleModelRequest();
        $request->setVisitor($vehicleModelVisitor);
//        global $testResponse;
/*        $testResponse = '<?xml version="1.0" encoding="utf-8"?><response>  <head>    <businessNo>BTX202412021401558612</businessNo>    <resultCode>1</resultCode>    <errorMsg>车型查询成功</errorMsg>  </head>  <body>    <vehicles>      <vehicle>        <modelCode>YUD1012BYD</modelCode>        <modelName>比亚迪BYD6420S5M多用途乘用车</modelName>        <brand>比亚迪</brand>        <purchasePrice>74900</purchasePrice>        <seat>5</seat>        <capacity>1.497</capacity>        <importFlag>1</importFlag>        <weight>1325</weight>        <tonnage></tonnage>        <modelDesc>手动档 尊荣型 国Ⅴ</modelDesc>        <marketDate>201604</marketDate>        <platformModelCode>BBYDYAUD0005</platformModelCode>        <noticeType>BYD6420S5M</noticeType>        <fuelType>A</fuelType>        <vehicleClassCode>IC02</vehicleClassCode>        <power>75</power>        <brandId>BYA</brandId>        <issueDate></issueDate>        <firstRegistrationDate></firstRegistrationDate>        <vehicleStyleUniqueId></vehicleStyleUniqueId>      </vehicle>      <vehicle>        <modelCode>YUD1011BYD</modelCode>        <modelName>比亚迪BYD6420S5M多用途乘用车</modelName>        <brand>比亚迪</brand>        <purchasePrice>69900</purchasePrice>        <seat>5</seat>        <capacity>1.497</capacity>        <importFlag>1</importFlag>        <weight>1325</weight>        <tonnage></tonnage>        <modelDesc>手动档 尊贵型 国Ⅴ</modelDesc>        <marketDate>201604</marketDate>        <platformModelCode>BBYDYAUD0004</platformModelCode>        <noticeType>BYD6420S5M</noticeType>        <fuelType>A</fuelType>        <vehicleClassCode>IC02</vehicleClassCode>        <power>75</power>        <brandId>BYA</brandId>        <issueDate></issueDate>        <firstRegistrationDate></firstRegistrationDate>        <vehicleStyleUniqueId></vehicleStyleUniqueId>      </vehicle>      <vehicle>        <modelCode>YUD1010BYD</modelCode>        <modelName>比亚迪BYD6420S5M多用途乘用车</modelName>        <brand>比亚迪</brand>        <purchasePrice>64900</purchasePrice>        <seat>5</seat>        <capacity>1.497</capacity>        <importFlag>1</importFlag>        <weight>1325</weight>        <tonnage></tonnage>        <modelDesc>手动档 豪华型 国Ⅴ</modelDesc>        <marketDate>201604</marketDate>        <platformModelCode>BBYDYAUD0003</platformModelCode>        <noticeType>BYD6420S5M</noticeType>        <fuelType>A</fuelType>        <vehicleClassCode>IC02</vehicleClassCode>        <power>75</power>        <brandId>BYA</brandId>        <issueDate></issueDate>        <firstRegistrationDate></firstRegistrationDate>        <vehicleStyleUniqueId></vehicleStyleUniqueId>      </vehicle>      <vehicle>        <modelCode>YUD1009BYD</modelCode>        <modelName>比亚迪BYD6420S5M多用途乘用车</modelName>        <brand>比亚迪</brand>        <purchasePrice>57900</purchasePrice>        <seat>5</seat>        <capacity>1.497</capacity>        <importFlag>1</importFlag>        <weight>1325</weight>        <tonnage></tonnage>        <modelDesc>手动档 舒适型 国Ⅴ</modelDesc>        <marketDate>201604</marketDate>        <platformModelCode>BBYDYAUC0001</platformModelCode>        <noticeType>BYD6420S5M</noticeType>        <fuelType>A</fuelType>        <vehicleClassCode>IC02</vehicleClassCode>        <power>75</power>        <brandId>BYA</brandId>        <issueDate></issueDate>        <firstRegistrationDate></firstRegistrationDate>        <vehicleStyleUniqueId></vehicleStyleUniqueId>      </vehicle>      <vehicle>        <modelCode>YUD1008BYD</modelCode>        <modelName>比亚迪BYD6420S5M多用途乘用车</modelName>        <brand>比亚迪</brand>        <purchasePrice>59900</purchasePrice>        <seat>5</seat>        <capacity>1.497</capacity>        <importFlag>1</importFlag>        <weight>1325</weight>        <tonnage></tonnage>        <modelDesc>手动档 标准型 国Ⅴ</modelDesc>        <marketDate>201604</marketDate>        <platformModelCode>BBYDYAUB0001</platformModelCode>        <noticeType>BYD6420S5M</noticeType>        <fuelType>A</fuelType>        <vehicleClassCode>IC02</vehicleClassCode>        <power>75</power>        <brandId>BYA</brandId>        <issueDate></issueDate>        <firstRegistrationDate></firstRegistrationDate>        <vehicleStyleUniqueId></vehicleStyleUniqueId>      </vehicle>      <vehicle>        <modelCode>YUD1007BYD</modelCode>        <modelName>比亚迪BYD6420S5M多用途乘用车</modelName>        <brand>比亚迪</brand>        <purchasePrice>53900</purchasePrice>        <seat>5</seat>        <capacity>1.497</capacity>        <importFlag>1</importFlag>        <weight>1325</weight>        <tonnage></tonnage>        <modelDesc>手动档 基本型 国Ⅴ</modelDesc>        <marketDate>201604</marketDate>        <platformModelCode>BBYDYAUA0001</platformModelCode>        <noticeType>BYD6420S5M</noticeType>        <fuelType>A</fuelType>        <vehicleClassCode>IC02</vehicleClassCode>        <power>75</power>        <brandId>BYA</brandId>        <issueDate></issueDate>        <firstRegistrationDate></firstRegistrationDate>        <vehicleStyleUniqueId></vehicleStyleUniqueId>      </vehicle>      <vehicle>        <modelCode>YUD1023BYD</modelCode>        <modelName>比亚迪BYD6420S5M多用途乘用车</modelName>        <brand>比亚迪</brand>        <purchasePrice>58900</purchasePrice>        <seat>5</seat>        <capacity>1.497</capacity>        <importFlag>1</importFlag>        <weight>1325</weight>        <tonnage></tonnage>        <modelDesc>手动档 全景天窗版型 国Ⅴ</modelDesc>        <marketDate>201710</marketDate>        <platformModelCode>BBYDYAUD0014</platformModelCode>        <noticeType>BYD6420S5M</noticeType>        <fuelType>A</fuelType>        <vehicleClassCode>IC02</vehicleClassCode>        <power>80</power>        <brandId>BYA</brandId>        <issueDate></issueDate>        <firstRegistrationDate></firstRegistrationDate>        <vehicleStyleUniqueId></vehicleStyleUniqueId>      </vehicle>      <vehicle>        <modelCode>YUD1024BYD</modelCode>        <modelName>比亚迪BYD6420S5M多用途乘用车</modelName>        <brand>比亚迪</brand>        <purchasePrice>64900</purchasePrice>        <seat>5</seat>        <capacity>1.497</capacity>        <importFlag>1</importFlag>        <weight>1325</weight>        <tonnage></tonnage>        <modelDesc>手动档 4G畅享版 国Ⅴ</modelDesc>        <marketDate>201710</marketDate>        <platformModelCode>BBYDYAUD0015</platformModelCode>        <noticeType>BYD6420S5M</noticeType>        <fuelType>A</fuelType>        <vehicleClassCode>IC02</vehicleClassCode>        <power>80</power>        <brandId>BYA</brandId>        <issueDate></issueDate>        <firstRegistrationDate></firstRegistrationDate>        <vehicleStyleUniqueId></vehicleStyleUniqueId>      </vehicle>      <vehicle>        <modelCode>YUD1020BYD</modelCode>        <modelName>比亚迪BYD6420S5M多用途乘用车</modelName>        <brand>比亚迪</brand>        <purchasePrice>51900</purchasePrice>        <seat>5</seat>        <capacity>1.497</capacity>        <importFlag>1</importFlag>        <weight>1325</weight>        <tonnage></tonnage>        <modelDesc>手动档 酷炫时尚型 国Ⅴ</modelDesc>        <marketDate>201704</marketDate>        <platformModelCode>BBYDYAUC0004</platformModelCode>        <noticeType>BYD6420S5M</noticeType>        <fuelType>A</fuelType>        <vehicleClassCode>IC02</vehicleClassCode>        <power>80</power>        <brandId>BYA</brandId>        <issueDate></issueDate>        <firstRegistrationDate></firstRegistrationDate>        <vehicleStyleUniqueId></vehicleStyleUniqueId>      </vehicle>      <vehicle>        <modelCode>YUD1021BYD</modelCode>        <modelName>比亚迪BYD6420S5M多用途乘用车</modelName>        <brand>比亚迪</brand>        <purchasePrice>45900</purchasePrice>        <seat>5</seat>        <capacity>1.497</capacity>        <importFlag>1</importFlag>        <weight>1325</weight>        <tonnage></tonnage>        <modelDesc>手动档 酷炫活力型 国Ⅴ</modelDesc>        <marketDate>201704</marketDate>        <platformModelCode>BBYDYAUB0004</platformModelCode>        <noticeType>BYD6420S5M</noticeType>        <fuelType>A</fuelType>        <vehicleClassCode>IC02</vehicleClassCode>        <power>80</power>        <brandId>BYA</brandId>        <issueDate></issueDate>        <firstRegistrationDate></firstRegistrationDate>        <vehicleStyleUniqueId></vehicleStyleUniqueId>      </vehicle>      <vehicle>        <modelCode>YUD1022BYD</modelCode>        <modelName>比亚迪BYD6420S5M多用途乘用车</modelName>        <brand>比亚迪</brand>        <purchasePrice>54900</purchasePrice>        <seat>5</seat>        <capacity>1.497</capacity>        <importFlag>1</importFlag>        <weight>1325</weight>        <tonnage></tonnage>        <modelDesc>手动档 酷炫互联型 国Ⅴ</modelDesc>        <marketDate>201704</marketDate>        <platformModelCode>BBYDYAUD0013</platformModelCode>        <noticeType>BYD6420S5M</noticeType>        <fuelType>A</fuelType>        <vehicleClassCode>IC02</vehicleClassCode>        <power>80</power>        <brandId>BYA</brandId>        <issueDate></issueDate>        <firstRegistrationDate></firstRegistrationDate>        <vehicleStyleUniqueId></vehicleStyleUniqueId>      </vehicle>    </vehicles>  </body></response>';*/
        /*** @var VehicleModelResponse $response */
        $response = $this->execute($request);
        return $response;
    }

    /**
     * 续保查询
     * @param RenewalInquiryVisitor $renewalInquiryVisitor
     * @return RenewalInquiryResponse
     */
    public function renewalInquiry(RenewalInquiryVisitor $renewalInquiryVisitor)
    {
        $request = new RenewalInquiryRequest();
        $request->setVisitor($renewalInquiryVisitor);

        /*** @var RenewalInquiryResponse $response */
        $response = $this->execute($request);
        return $response;
    }

    /**
     * 车辆实际价格接口
     * @param VehicleActualValueVisitor $vehicleActualValueVisitor
     * @return
     */
    public function vehicleActualValue(VehicleActualValueVisitor $vehicleActualValueVisitor)
    {
        $request = new VehicleActualValueRequest();
        $request->setVisitor($vehicleActualValueVisitor);

        /*** @var VehicleActualValueResponse $response */
        $response = $this->execute($request);
        return $response;
    }

    /**
     * 询价前置
     * @param PremiumInquiryVisitor $premiumInquiryVisitor
     * @return
     */
    public function preInquiry(PremiumInquiryVisitor $premiumInquiryVisitor)
    {

    }

    public function validateCar(PremiumInquiryVisitor $premiumInquiryVisitor)
    {
        $checkRequest = new VehicleCheckRequest();
        $checkRequest->setVisitor($premiumInquiryVisitor);
        /*** @var VehicleCheckResponse $response */
        $response = $this->execute($checkRequest);
        if($response->isSuccess()){
            $response->printer->ext['cInspectClaim'] = $premiumInquiryVisitor->getExtInfoVisitor()->argc['cInspectClaim'] ?? '';
        }
        return $response;
    }

    /**
     * 询价
     * @param PremiumInquiryVisitor $premiumInquiryVisitor
     * @return
     * @throws \Exception
     */
    public function premiumInquiry(PremiumInquiryVisitor $premiumInquiryVisitor)
    {
        $request = new PremiumInquiryRequest();
        $request->setVisitor($premiumInquiryVisitor);
//        global $testResponse;
/*        $testResponse = '<?xml version="1.0" encoding="utf-8"?><response>  <head>    <businessNo>BTX202501091002418363</businessNo>    <resultCode>01</resultCode>    <errorMsg>成功</errorMsg>  </head>  <body>    <base>      <quotationNo>e127dead-0f81736389581</quotationNo>      <totalPremium>3324.27</totalPremium>      <totalBasePremium>3743.26</totalBasePremium>      <vciEffectiveDate>2025-01-10 00:00:00</vciEffectiveDate>      <vciExpiryDate>2026-01-09 23:59:59</vciExpiryDate>      <vciPremium>2374.27</vciPremium>      <vciDiscount>0.85</vciDiscount>      <vciBasePremium>2793.26</vciBasePremium>      <tciEffectiveDate>2025-01-10 00:00:00</tciEffectiveDate>      <tciExpiryDate>2026-01-09 23:59:59</tciExpiryDate>      <tciPremium>950.0</tciPremium>      <tciDiscount>1.0</tciDiscount>      <tciBasePremium>950.0</tciBasePremium>      <claimAmount>0</claimAmount>      <trafficIllegalAmount></trafficIllegalAmount>      <ncdRate>1.0</ncdRate>      <channelRate></channelRate>      <uwRate></uwRate>      <illegalRate>1.0</illegalRate>      <tciCheckCode></tciCheckCode>      <vciCheckCode></vciCheckCode>      <minChannelRate></minChannelRate>      <minUwRate></minUwRate>      <maxChannelRate></maxChannelRate>      <maxUwRate></maxUwRate>      <maxValue></maxValue>      <minValue></minValue>      <actualValue></actualValue>      <tciDemandNo></tciDemandNo>      <vciDemandNo></vciDemandNo>      <discountByPremium>0</discountByPremium>      <minVciDiscount></minVciDiscount>      <maxVciDiscount></maxVciDiscount>      <tciBrokerFeeRate></tciBrokerFeeRate>      <vciBrokerFeeRate></vciBrokerFeeRate>      <cInspectClaim>11</cInspectClaim>      <cBusTypeJq>2</cBusTypeJq>      <cBusTypeSy>2</cBusTypeSy>      <insureYears>0</insureYears>      <claimTimes>0</claimTimes>      <claimAdjustLevel>0</claimAdjustLevel>      <pricingRate>0.85</pricingRate>      <minPricingRate>00.81</minPricingRate>      <maxPricingRate>1.5</maxPricingRate>      <riskPriceScore>10</riskPriceScore>    </base>    <coverages>      <coverage>        <productCode>MAUTO</productCode>        <coverageCode>COMPAUTO</coverageCode>        <limitAmount>200000</limitAmount>        <premium>950.0</premium>        <basePremium>950.0</basePremium>        <benchMarkPremium></benchMarkPremium>        <dicsount>1.0</dicsount>        <campaignPremium></campaignPremium>      </coverage>      <coverage>        <productCode>GAUTO</productCode>        <coverageCode>AOD</coverageCode>        <limitAmount>52660</limitAmount>        <premium>1581.43</premium>        <basePremium>1860.51</basePremium>        <benchMarkPremium>1860.51</benchMarkPremium>        <dicsount>0.85</dicsount>        <campaignPremium></campaignPremium>      </coverage>      <coverage>        <productCode>GAUTO</productCode>        <coverageCode>ATP</coverageCode>        <limitAmount>2000000</limitAmount>        <premium>707.77</premium>        <basePremium>832.67</basePremium>        <benchMarkPremium>832.67</benchMarkPremium>        <dicsount>0.85</dicsount>        <campaignPremium></campaignPremium>      </coverage>      <coverage>        <productCode>GAUTO</productCode>        <coverageCode>ADL</coverageCode>        <limitAmount>10000</limitAmount>        <premium>24.05</premium>        <basePremium>28.29</basePremium>        <benchMarkPremium>28.29</benchMarkPremium>        <dicsount>0.85</dicsount>        <campaignPremium></campaignPremium>      </coverage>      <coverage>        <productCode>GAUTO</productCode>        <coverageCode>APL</coverageCode>        <limitAmount>40000</limitAmount>        <premium>61.02</premium>        <basePremium>71.79</basePremium>        <benchMarkPremium>71.79</benchMarkPremium>        <dicsount>0.85</dicsount>        <campaignPremium></campaignPremium>      </coverage>    </coverages>    <tax>      <taxStatus>02</taxStatus>      <taxActual>300.0</taxActual>      <previousPay></previousPay>      <lateFee>57.6</lateFee>      <totalTax>957.6</totalTax>      <relifReason></relifReason>      <deductionType></deductionType>      <deductionProportion></deductionProportion>      <deductionAmount></deductionAmount>      <taxStartDate>20250101</taxStartDate>      <taxEndDate>20251231</taxEndDate>      <taxCompancyCode></taxCompancyCode>      <taxCompancyName></taxCompancyName>      <paidFreeCertificate></paidFreeCertificate>    </tax>    <clauses>      <clause>        <clauseCode>003</clauseCode>        <clauseName>003</clauseName>        <content>收到本保单请立即核对，如无异议，即视为同意合同条款及约定的全部内容。</content>        <flag>2</flag>        <productCode>GAUTO</productCode>      </clause>      <clause>        <clauseCode>004</clauseCode>        <clauseName>004</clauseName>        <content>本车行驶证车主为：XXX 。</content>        <flag>3</flag>        <productCode>GAUTO</productCode>      </clause>      <clause>        <clauseCode>006</clauseCode>        <clauseName>006</clauseName>        <content>被保险车辆在保险期限内若改变使用性质导致被保险机动车辆危险程度显著增加发生保险事故，保险人不负责赔偿。</content>        <flag>2</flag>        <productCode>GAUTO</productCode>      </clause>      <clause>        <clauseCode>007</clauseCode>        <clauseName>007</clauseName>        <content>投保时被保险车辆无行驶证，出险后以发动机号机和车架号为准。</content>        <flag>2</flag>        <productCode>GAUTO</productCode>      </clause>      <clause>        <clauseCode>008</clauseCode>        <clauseName>008</clauseName>        <content>人员伤亡事故中医疗费用赔付标准按照《道路交通事故受伤人员临床诊疗指南》和国家基本医疗保险的同类医疗费用标准确定；出险时,需在县级(含)以上公立医院或社保定点医疗机构就诊。</content>        <flag>2</flag>        <productCode>GAUTO</productCode>      </clause>      <clause>        <clauseCode>009</clauseCode>        <clauseName>009</clauseName>        <content>本保单项下新增设备为： XXX ，设备价值为 XXX 元，保险金额为 XXX。</content>        <flag>3</flag>        <productCode>GAUTO</productCode>      </clause>      <clause>        <clauseCode>012</clauseCode>        <clauseName>012</clauseName>        <content>本保单承保的挂车，为 XXX 号牵引车的无动力挂车。</content>        <flag>3</flag>        <productCode>GAUTO</productCode>      </clause>      <clause>        <clauseCode>013</clauseCode>        <clauseName>013</clauseName>        <content>保险车辆发生保险事故后被保险人必须第一时间通知本公司或报交警处理，凡通知不及时或未经本公司同意擅自撤离现场，造成我司无法及时查勘第一现场确定事故责任本公司有权拒绝赔偿。</content>        <flag>2</flag>        <productCode>GAUTO</productCode>      </clause>      <clause>        <clauseCode>014</clauseCode>        <clauseName>014</clauseName>        <content>标的车辆投保时 XXX 部位存在损失（详见验车报告及验车照片）；以上约定部位在保险期间内发生保险事故时，保险人扣减原有损失后计算赔偿。</content>        <flag>3</flag>        <productCode>GAUTO</productCode>      </clause>      <clause>        <clauseCode>038</clauseCode>        <clauseName>038</clauseName>        <content>本标的车贷款起止时间XXX，贷款金额XXX。</content>        <flag>3</flag>        <productCode>GAUTO</productCode>      </clause>      <clause>        <clauseCode>039</clauseCode>        <clauseName>039</clauseName>        <content>保险期间内，如发生本保险合同约定的保险事故造成被保险车辆损失或第三者财产损失时，可与保险人协商采取以修复方式进行实物赔付，也可以现金方式赔付。以修复方式实物赔付的，双方可签订相应的协议具体约定相关内容。</content>        <flag>2</flag>        <productCode>GAUTO</productCode>      </clause>      <clause>        <clauseCode>994</clauseCode>        <clauseName>994</clauseName>        <content>浙商保险·托付永远VIP尊享客户。</content>        <flag>2</flag>        <productCode>GAUTO</productCode>      </clause>      <clause>        <clauseCode>002</clauseCode>        <clauseName>002</clauseName>        <content>本保险单所承保的保险标的发生赔款时，除法院或我公司认可的代索赔单位，及银行贷款指定的第一索赔权益人以外，以转帐划款的方式直接支付给被保险人。</content>        <flag>2</flag>        <productCode>MAUTO</productCode>      </clause>      <clause>        <clauseCode>003</clauseCode>        <clauseName>003</clauseName>        <content>因国家税务总局规定：‘车船使用税不能提前征收’，故该车的车船使用税已征收至20XXX年，20XXX年的车船税经车主同意，在下一年度投保时征收。</content>        <flag>3</flag>        <productCode>MAUTO</productCode>      </clause>      <clause>        <clauseCode>004</clauseCode>        <clauseName>004</clauseName>        <content>本车行驶证车主为：XXX 。</content>        <flag>3</flag>        <productCode>MAUTO</productCode>      </clause>      <clause>        <clauseCode>006</clauseCode>        <clauseName>006</clauseName>        <content>本保单承保的牵引车拖载的挂车车号为 XXX 号。</content>        <flag>3</flag>        <productCode>MAUTO</productCode>      </clause>      <clause>        <clauseCode>008</clauseCode>        <clauseName>008</clauseName>        <content>该车临时上道路行驶，行驶路线由XXX至XXX。</content>        <flag>3</flag>        <productCode>MAUTO</productCode>      </clause>      <clause>        <clauseCode>013</clauseCode>        <clauseName>013</clauseName>        <content>本标的车贷款起止时间XXX，贷款金额XXX。</content>        <flag>3</flag>        <productCode>MAUTO</productCode>      </clause>    </clauses>    <deviceDomains/>    <nonVehicleProducts/>  </body></response>';*/
        /*** @var PremiumInquiryResponse $response */
        $response = $this->execute($request);
//        $testResponse = '';
        if($response->isSuccess()){
            $response->printer->argc['applyLicenseNo'] = $premiumInquiryVisitor->getApplicantVisitor()->certificateNo;
            $response->buildCoverage($premiumInquiryVisitor->getVehicleVisitor()->isNewEnergy, $premiumInquiryVisitor->getCoverageVisitorList());
            //非车
            $nonCarInquiryPrinter = new NonCarInquiryPrinter();
            $totalPremium = 0;
            foreach ($premiumInquiryVisitor->getNonCarInquiryVisitor()->getNonCarList() as $item) {
                /*** @var $item NonCarProductVisitor */
                $single = new NonCarInquirySinglePrinter();
                $single->premium = $item->premium;
                $single->planCode = $item->planCode;
                $single->productCode = $item->productCode;
                $single->statusCode = 'success';
                $totalPremium += $single->premium * $item->insuredNum;
                $nonCarInquiryPrinter->noCarInquirySingleAppend($single);
            }
            $nonCarInquiryPrinter->totalPremium = $totalPremium;
            $response->printer->nonCarInquiryPrinter = $nonCarInquiryPrinter;
        }

        return $response;
    }

    /**
     * 核保
     * @param PremiumInquiryVisitor $premiumInquiryVisitor
     * @return
     */
    public function underwriting(PremiumInquiryVisitor $premiumInquiryVisitor)
    {
        $request = new UnderwritingRequest();
        $request->setVisitor($premiumInquiryVisitor);
//global $testResponse;
/*$testResponse = '<?xml version="1.0" encoding="utf-8"?><response>  <head>    <businessNo>BTX202412231549298440</businessNo>    <resultCode>1</resultCode>    <errorMsg></errorMsg>  </head>  <body>    <base>      <uwFlag>9</uwFlag>      <uwMsg>商业：验车业务，请人工审核。【验车009】;验车车架号与车辆车架号不一致，请审核【验车010】;  交强：验车业务，请人工审核。【验车009】;验车车架号与车辆车架号不一致，请审核【验车010】;</uwMsg>      <vciProposalNo>767510103652024N8N833ei</vciProposalNo>      <tciProposalNo>767510103302024TnkwI8Hd</tciProposalNo>      <orderNo>P1734940243485</orderNo>      <paymentDueDate>2024-12-23 23:50:00</paymentDueDate>    </base>    <nonVehicleProducts>      <nonVehicleProduct>        <productCode></productCode>        <planCode></planCode>        <proposalNo></proposalNo>        <effectiveDate></effectiveDate>        <expiryDate></expiryDate>      </nonVehicleProduct>    </nonVehicleProducts>  </body></response>';*/

        /**@var UnderwritingResponse $response **/
        $response = $this->execute($request);
//$testResponse = '';
        //上传文件
        if(!empty($premiumInquiryVisitor->getFileList()) && $response->isSuccess()){
            $printer = $response->printer;
            foreach ($premiumInquiryVisitor->getFileList() as $value){
                $uploadFileVisitor = new UploadFileVisitor();
                $uploadFileVisitor->argc = array_merge($premiumInquiryVisitor->getExtInfoVisitor()->argc,$printer->argc);
                $uploadFileVisitor->ciInquiryNo = $printer->ciInquiryNo;
                $uploadFileVisitor->biInquiryNo = $printer->biInquiryNo;
                $uploadFileVisitor->inquiryNo = $printer->argc['quotationNo'] ?? '';
                $uploadFileVisitor->fileAppend($value['type'], $value['url'], $value['base64']);
                $this->uploadImg($uploadFileVisitor);
            }
        }
        //非车数据回填重构
//        /*** @var PremiumUnderwritingPrinter $printer */
//        $printer = $response->getPrinter();
//        if ($printer->noCarUnderwritingPrinter->statusCode == 'success' && !empty($premiumInquiryVisitor->getNonCarUnderwritingVisitor()->getNonCarList())) {
//
//            /*** @var NonCarProductVisitor $nonProduct */
//            $nonProduct = $premiumInquiryVisitor->getNonCarUnderwritingVisitor()->getNonCarList()[0];
//
//            $nonCarList = $printer->noCarUnderwritingPrinter->getNonCarInquiryList();
//
//            foreach ($nonCarList as &$value) {
//                /*** @var NonCarInquirySinglePrinter $value */
//                $value->productCode = $nonProduct->productCode;
//                $value->planCode = $nonProduct->planCode;
//            }
//        }
//
//        $response->printer = $printer;
        return $response;
    }

    /**
     * 获取支付链接
     * @param PolicyPaymentVisitor $paymentVisitor
     * @return
     */
    public function policyPayment(PolicyPaymentVisitor $paymentVisitor)
    {
        $request = new PolicyPaymentRequest();
        $request->setVisitor($paymentVisitor);
//global $testResponse;
/*$testResponse = '<?xml version="1.0" encoding="utf-8"?><response>  <head>    <businessNo>BTX202412121107164342</businessNo>    <resultCode>1</resultCode>    <errorMsg></errorMsg>  </head>  <body>    <base>      <payUrl>https://weixin1.zsins.com/H5Sign/?NId=P1733972892568&CDataSrc=68</payUrl>      <paymentNo></paymentNo>      <payRepProperties>        <payRepEntryList>          <entry>            <key>orderId</key>            <value>240235465962</value>          </entry>        </payRepEntryList>      </payRepProperties>    </base>  </body></response>';*/
        /**@var PolicyPaymentRequest $response * */
        $response = $this->execute($request);

        return $response;
    }

    public function proposalStatus(ProposalStatusVisitor $proposalStatusVisitor)
    {
        $request = new OrderStatusQueryRequest();
        $request->setVisitor($proposalStatusVisitor);

        /**
         * @var OrderStatusQueryResponse $response
         */
        $response = $this->execute($request);
        return $response;
    }

    /**
     * 核保撤销
     * @param ProposalRecallVisitor $revokeVisitor
     * @return UnderwritingRecallResponse
     */
    public function proposalRecall(ProposalRecallVisitor $revokeVisitor)
    {
        $request = new UnderwritingRecallRequest();
        $request->setVisitor($revokeVisitor);

        /**
         * @var UnderwritingRecallResponse $response
         */
        $response = $this->execute($request);
        return $response;
    }

    /**
     * 撤单接口
     * @param UnderwritingRecallVisitor $recallVisitor
     * @return CancelOrderResponse
     */
    public function underwritingRecall(UnderwritingRecallVisitor $recallVisitor)
    {
        $request = new OrderCancelRequest();
        $request->setVisitor($recallVisitor);

        /**
         * @var CancelOrderResponse $response
         */
        $response = $this->execute($request);
        return $response;
    }

    public function EPolicyDownload(EPolicyDownloadVisitor $EPolicyVisitor)
    {
        $request = new ElecPolicyDownloadRequest();
        $request->setVisitor($EPolicyVisitor);

        /**
         * @var ElecPolicyDownloadResponse $response
         */
        $response = $this->execute($request);
        return $response;
    }

    public function policyInfo(PolicyInfoVisitor $policyInfoVisitor)
    {
        $request = new OrderStatusQueryRequest();
        $request->setVisitor($policyInfoVisitor);

        /**
         * @var OrderStatusQueryResponse $response
         */
        $response = $this->execute($request);
        return $response;
    }

    public function UploadFile(UploadFileVisitor $uploadFileVisitor)
    {
        $response = new UploadFileResponse();
        $response->setCode(200);
        return $response;
    }

    public function uploadImg(UploadFileVisitor $uploadFileVisitor)
    {
        $request = new UploadFileRequest();
        $request->setVisitor($uploadFileVisitor);
        /**
         * @var UploadFileResponse $response
         */
        $response = $this->execute($request);
        return $response;
    }


    /**
     * 非车产品列表
     * @param NonCarProductListVisitor $nonCarProductListVisitor
     * @return NonCarProductListResponse
     * @version 4.0
     */
    public function nonCarProductList(NonCarProductListVisitor $nonCarProductListVisitor): NonCarProductListResponse
    {
        $request = new NonCarProductListRequest();
        $request->setVisitor($nonCarProductListVisitor);
//        global $testResponse;
/*        $testResponse = '<?xml version="1.0" encoding="utf-8"?><response>  <head>    <businessNo>BTX202412231047141669</businessNo>    <resultCode>01</resultCode>    <errorMsg>成功</errorMsg>  </head>  <body>    <nonVehicleProducts>      <nonVehicleProduct>        <productCode>C036</productCode>        <productName>机动车驾乘人员意外伤害保险（四川版）</productName>        <planCode>C036P003_005</planCode>        <planName>2~5座非营客300元（四川）</planName>        <premium>300</premium>        <insuredAmount>1465000</insuredAmount>        <maxPurchaseNumber>5</maxPurchaseNumber>        <maxInsuredAge>99</maxInsuredAge>        <minInsuredAge>18</minInsuredAge>        <productDetails>          <productDetail>            <coverage>驾驶非营运汽车意外伤害</coverage>            <sumInsured>500000</sumInsured>          </productDetail>          <productDetail>            <coverage>乘坐非营运汽车意外伤害</coverage>            <sumInsured>800000</sumInsured>          </productDetail>          <productDetail>            <coverage>意外伤害医疗</coverage>            <sumInsured>100000</sumInsured>          </productDetail>          <productDetail>            <coverage>意外伤害医疗</coverage>            <sumInsured>20000</sumInsured>          </productDetail>          <productDetail>            <coverage>住院津贴</coverage>            <sumInsured>45000</sumInsured>          </productDetail>        </productDetails>      </nonVehicleProduct>      <nonVehicleProduct>        <productCode>C036</productCode>        <productName>机动车驾乘人员意外伤害保险（四川版）</productName>        <planCode>C036P003_005</planCode>        <planName>2~5座非营客300元（四川）</planName>        <premium>300</premium>        <insuredAmount>1465000</insuredAmount>        <maxPurchaseNumber>5</maxPurchaseNumber>        <maxInsuredAge>99</maxInsuredAge>        <minInsuredAge>18</minInsuredAge>        <productDetails>          <productDetail>            <coverage>驾驶非营运汽车意外伤害</coverage>            <sumInsured>500000</sumInsured>          </productDetail>          <productDetail>            <coverage>乘坐非营运汽车意外伤害</coverage>            <sumInsured>800000</sumInsured>          </productDetail>          <productDetail>            <coverage>意外伤害医疗</coverage>            <sumInsured>100000</sumInsured>          </productDetail>          <productDetail>            <coverage>意外伤害医疗</coverage>            <sumInsured>20000</sumInsured>          </productDetail>          <productDetail>            <coverage>住院津贴</coverage>            <sumInsured>45000</sumInsured>          </productDetail>        </productDetails>      </nonVehicleProduct>    </nonVehicleProducts>  </body></response>';*/
        /**
         * @var NonCarProductListResponse $response
         */
        $response = $this->execute($request);
        return $response;
    }

    public function nonCarInquiry(NonCarInquiryVisitor $nonCarInquiryVisitor)
    {
        // TODO: Implement nonCarInquiry() method.
    }

    public function nonCarUnderwriting(NonCarInquiryVisitor $inquiryPrinter)
    {
        // TODO: Implement nonCarUnderwriting() method.
    }
}
